clear
rng default
load IdSetM_final_x1
IdSetM{1}=IdSetM_final_x1;
load IdSetM_final_x2
IdSetM{2}=IdSetM_final_x2;
load IdSetM_final_x3
IdSetM{3}=IdSetM_final_x3; 
load IdSetM_final_x4
IdSetM{4}=IdSetM_final_x4;
load IdSetM_final_x5
IdSetM{4}=IdSetM_final_x5;
load IdSetW_final_y1
IdSetW{1}=IdSetW_final_y1;
load IdSetW_final_y2
IdSetW{2}=IdSetW_final_y2;
load IdSetW_final_y3
IdSetW{3}=IdSetW_final_y3; 
load IdSetW_final_y4
IdSetW{4}=IdSetW_final_y4;
load IdSetW_final_y5
IdSetW{4}=IdSetW_final_y5;

ntypes_m=5;
ntypes_w=5;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%% Projections in one dimension %%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Phi=cell(ntypes_m, ntypes_w);
for i=2:ntypes_m+1
    for j=2:ntypes_w+1
        M=unique(IdSetM{i-1}(:,j), 'rows', 'stable'); 
        W=unique(IdSetW{j-1}(:,i), 'rows', 'stable');
        sm=size(M,1);
        temp=cell(sm,1);
        for k=1:sm
            temp{k}=M(k)+W(:); 
        end
        temp=vertcat(temp{:});
        Phi{i-1,j-1}=[min(temp); max(temp)];
    end
end

save('Phi_intervals.mat', 'Phi')

load U_CS
load V_CS

Phi_CS=U_CS+V_CS;
save('Phi_CS.mat', 'Phi_CS')


